*
*                  Mediation Experiment Data Preparation
*
*                                 2025-06-18
*  
*-------------------------------------------------SETUP

* Setting working directory
cd "Replication Materials\Data"

*-----------------------------------------APPENDING & MERGING DATA


*Append all EVMB datasets together
append using "EVMB_ZB.dta" "EVMB_MB.dta" "EVMB_LI.dta" "EVMB_KE.dta" "EVMB_LU.dta"

gen id= _n

save "EVMB_All.dta", replace 

*---------------------------------------PREP VARIABLES


*Mediation treatment
gen mediator="BLANK" if evmb_q16!=.
replace mediator="Observability" if evmb_q16==3
replace mediator="Competence" if evmb_q16==4
replace mediator="Distribution: Equally to all villages" if evmb_q16==2
replace mediator="Distribution: Equally to all ethnic groups" if evmb_q16==5


*--------------------------------Attributes Fix

*Ethnicity
rename evmb_q2 ethnicity_at, replace

*Religion
rename evmb_q3 religion_at, replace 

*Age 
rename evmb_q11 age_at, replace 

*Origin
rename evmb_q12 origin_at, replace 

*Living Status 
rename evmb_q13 livingstatus_at, replace

*Gender 
rename evmb_q14 gender_at, replace

*Class 
rename evmb_q15 class_at, replace


*------------------------------------Dependent Variables 

*Vote Binary
gen vote=0 if (evmb_q17!=. & evmb_q17!=5 & evmb_q17!=6)
replace vote=1 if (evmb_q17==1 | evmb_q17==2)

*Vote Ordinal
gen voteordinal=1 if (evmb_q17!=. & evmb_q17!=5 & evmb_q17!=6)
replace voteordinal=2 if evmb_q17==3
replace voteordinal=3 if evmb_q17==2
replace voteordinal=4 if evmb_q17==1
label define ordinal 1 "Not at all likely" 2 "Not likely" 3 "Somewhat likely" 4 "Very likely"
label value voteordinal ordinal 


*Spending Priorities 
gen spendprior=1 if (evmb_q18!=. & evmb_q18!=5 & evmb_q18!=6)
replace spendprior=2 if evmb_q18==3
replace spendprior=3 if evmb_q18==2
replace spendprior=4 if evmb_q18==1
label define ordinal 1 "Not at all likely" 2 "Not likely" 3 "Somewhat likely" 4 "Very likely"
label value spendprior ordinal 

*Moral
gen moral=1 if (evmb_q19!=. & evmb_q19!=5 & evmb_q19!=6)
replace moral=2 if evmb_q19==3
replace moral=3 if evmb_q19==2
replace moral=4 if evmb_q19==1
label value moral ordinal

*Help Women 
gen helpwomen=1 if (evmb_q20!=. & evmb_q20!=5 & evmb_q20!=6)
replace helpwomen=2 if evmb_q20==3
replace helpwomen=3 if evmb_q20==2
replace helpwomen=4 if evmb_q20==1
label value helpwomen ordinal

*Help Village
gen helpvillage=1 if (evmb_q21!=. & evmb_q21!=5 & evmb_q21!=6)
replace helpvillage=2 if evmb_q21==3
replace helpvillage=3 if evmb_q21==2
replace helpvillage=4 if evmb_q21==1
label value helpvillage ordinal

*Help Ethnic 
gen helpethnic=1 if (evmb_q22!=. & evmb_q22!=5 & evmb_q22!=6)
replace helpethnic=2 if evmb_q22==3
replace helpethnic=3 if evmb_q22==2
replace helpethnic=4 if evmb_q22==1
label value helpethnic ordinal

*Transparent 
gen transparent=1 if (evmb_q23!=. & evmb_q23!=5 & evmb_q23!=6)
replace transparent=2 if evmb_q23==3
replace transparent=3 if evmb_q23==2
replace transparent=4 if evmb_q23==1
label value transparent ordinal

*Mobilize 
gen mobilize=1 if (evmb_q24!=. & evmb_q24!=5 & evmb_q24!=6)
replace mobilize=2 if evmb_q24==3
replace mobilize=3 if evmb_q24==2
replace mobilize=4 if evmb_q24==1
label value mobilize ordinal

*Own Gain
gen owngain=1 if (evmb_q25!=. & evmb_q25!=5 & evmb_q25!=6)
replace owngain=2 if evmb_q25==3
replace owngain=3 if evmb_q25==2
replace owngain=4 if evmb_q25==1
label value owngain ordinal

*Win Elecion
gen winelection=1 if (evmb_q26!=. & evmb_q26!=5 & evmb_q26!=6)
replace winelection=2 if evmb_q26==3
replace winelection=3 if evmb_q26==2
replace winelection=4 if evmb_q26==1
label value winelection ordinal

*Find Out About Corruption
gen findcorrupt=1 if (evmb_q27!=. & evmb_q27!=5 & evmb_q27!=6)
replace findcorrupt=2 if evmb_q27==3
replace findcorrupt=3 if evmb_q27==2
replace findcorrupt=4 if evmb_q27==1
label value findcorrupt ordinal

*Sanction 
gen sanction=1 if (evmb_q28!=. & evmb_q28!=5 & evmb_q28!=6)
replace sanction=2 if evmb_q28==3
replace sanction=3 if evmb_q28==2
replace sanction=4 if evmb_q28==1
label value sanction ordinal


save "EVMB_All.dta", replace


*---------------COMBINING EXPERIMENT AND CTRL

*Append all CTRL datasets together
use "CTRL_KE.dta"
append using "CTRL_LI.dta" "CTRL_LU.dta" "CTRL_MB.dta" "CTRL_ZB.dta"
 
gen id=_n
 
save "CTRL_All.dta", replace 

clear

*Merge EVMB and CTRL together
use "EVMB_All.dta"

merge 1:1 SbjNum using "CTRL_All.dta"

keep if _merge==3

drop id _merge

gen id=_n

save "EVMB_CTRL.dta", replace

*--------------------------------------------------END